﻿using System;
using System.Collections.Generic;
using System.Windows.Media;

namespace OpenLS.Spreadsheet.Formats.Biff.Records
{
    internal class ClrtClientRecord : BiffRecord
    {
        List<Color> _colors = new List<Color>();
        protected override void ReadContent(BiffReaderContext context, int length)
        {
            ushort count = context.ReadUInt16();
            for (int i = 0; i < count; i++)
            {
                byte red = context.ReadByte();
                byte green = context.ReadByte();
                byte blue = context.ReadByte();
                byte alpha = context.ReadByte();
                _colors.Add(Color.FromArgb(alpha, red, green, blue));
            }
        }

        internal override BiffRecordType RecordType
        {
            get { return BiffRecordType.ClrtClient; }
        }

        internal override void WriteContent(BiffWriterWorkbookContext context)
        {
            context.WriteUInt16((ushort) _colors.Count);
            foreach (var color in _colors)
            {
                context.Write(color.R);
                context.Write(color.G);
                context.Write(color.B);
                context.Write(color.A);
            }
            }
    }
}